package com.gemalto.Kryptik.Gui;

import com.gemalto.Kryptik.Gui.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Component;
import javax.swing.text.JTextComponent;

public class CountedTextField extends JTextField implements CaretListener,ComboBoxEditor {

	private Counter counter;

	public CountedTextField(int maxLength, Counter c){
		super();	
		setDocument(new HexDocument(maxLength));
		addCaretListener(this);
		counter=c;
	}

	public void caretUpdate(CaretEvent e){
		if (counter!=null) counter.update((JTextComponent)this);
	}


	public Component getEditorComponent(){
		return (Component)this;
	}


	public Object getItem(){
		return (Object)getText();
	}

	public void setItem (Object item){
		if (item!=null) setText((String)item);
	}

}